{% extends 'base.html.twig' %}
{% import 'Import/app_import.html.twig' as appImport %}

{% block head_title %}{{ 'pipelines'|trans }} - {{ pipeline.name }}{% endblock %}

{% block heading_1 %}
    {{ appImport.heading({'level': 1, 'title': 'pipelines'|trans, 'link': {'url': path('pipelines')}}) }}
{% endblock %}

{% block heading_2 %}
    {{ appImport.heading({'level': 2, 'title': pipeline.name}) }}
{% endblock %}

{% block tabs %}
    {% include 'Modules/pipeline/pipeline_read_tabs.html.twig' with {'active': 'summary'} %}
{% endblock %}

{% block main_content %}
    {% embed 'Embed/block_embed.html.twig' %}
        {% import 'Import/app_import.html.twig' as appImport %}
        {% block content %}
            {{ appImport.heading({'level': 3, 'title': 'summary'|trans}) }}

            {% embed 'Embed/buttons_embed.html.twig' %}
                {% import 'Import/app_import.html.twig' as appImport %}
                {% block content %}
                    {% if is_granted('PIPELINE_DELETE', pipeline) %}
                        {{ appImport.buttonModal({
                            'id': 'PipelineDelete',
                            'title': 'delete'|trans,
                            'body': pipeline.name,
                            'href': path('pipelines_delete', {'name': pipeline.name}),
                        }) }}
                    {% endif %}

                    {% if is_granted('PIPELINE_COPY', pipeline) %}
                        <a class="btn btn-primary btn-sm" href="{{ path('pipelines_create', {'pipeline': pipeline.name}) }}">{{ 'copy'|trans }}</a>
                    {% endif %}
                {% endblock %}
            {% endembed %}

            {% if pipeline.description %}
                <p>
                    <strong>{{ 'description'|trans }}</strong><br>
                    {{ pipeline.description }}
                </p>
            {% endif %}

            {% if pipeline.version %}
                <p>
                    <strong>{{ 'version'|trans }}</strong><br>
                    {{ pipeline.version }}
                </p>
            {% endif %}

            {% if pipeline.onFailure and 0 < pipeline.onFailure|length %}
                <p>
                    <strong>{{ 'on_failure'|trans }}</strong><br>
                    <pre>{{ pipeline.onFailure|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
                </p>
            {% endif %}

            {% if pipeline.processors and 0 < pipeline.processors|length %}
                {{ appImport.heading({'level': 4, 'title': 'processors'|trans, 'badge': {'title': pipeline.processors|length}}) }}

                {% embed 'Embed/table_embed.html.twig' %}
                    {% block thead %}
                        <tr>
                            <th>{{ 'processor'|trans }}</th>
                            <th>{{ 'configuration'|trans }}</th>
                        </tr>
                    {% endblock %}

                    {% block tbody %}
                        {% for rows in pipeline.processors %}
                            {% for k, row in rows %}
                                <tr>
                                    <td>
                                        {{ k }}
                                    </td>
                                    <td>
                                        <pre>{{ row|json_encode(constant('JSON_PRETTY_PRINT')) }}</pre>
                                    </td>
                                </tr>
                            {% endfor %}
                        {% endfor %}
                    {% endblock %}
                {% endembed %}
            {% endif %}
        {% endblock %}
    {% endembed %}
{% endblock %}
